<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../fragments/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="decorator" content="default"/>
</head>
<body>
<div title="任务列表" style="padding:10px">
    <div id="tb" style="padding:3px">
        <span>选择任务类型:</span>
        <select id="condition" class="easyui-combobox" style="width:10%">
            <option value="0">当前任务</option>
            <option value="1">历史任务</option>
            <option value="2">全部任务</option>
        </select>
        <a href="#" class="easyui-linkbutton" plain="true" onclick="doSearch()">搜索</a>
    </div>
    <table id="dg"  class="easyui-datagrid" style="height:400px"
           url="${ctx}/aid_task/pageList"
           toolbar="#toolbar" pagination="true"
           rownumbers="true" fitColumns="true" singleSelect="true" data-options="queryParams: {
                'pageSize' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageSize;
                },
                'pageNumber' : function(){
                    return $('#dg').datagrid('getPager').pagination('options').pageNumber;
                }
            }">
        <thead>
        <tr>
            <th field="detail" width="50">任务内容</th>
            <th field="planName" width="50">所属预案</th>
            <th field='create_time' data-options="formatter:function(value,row,index){return dateFormatter(value);}" width="50">发布时间</th>
        </tr>
        </thead>
    </table>
    <div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editMem()">处理任务</a>
    </div>

    <div id="dlg" class="easyui-dialog" style="width:400px"
         closed="true" buttons="#dlg-buttons">
        <form id="fm" method="post" action="" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc">任务详情</div>
            <input type="hidden" name="ID">
            <input type="hidden" name="operation_code">
            <div  style="margin-bottom:10px">
                <input name="detail"  id="name" class="easyui-textbox" data-options="multiline:true" required="true" editable="false" label="任务内容描述:" style="width:100%;height: 40px">
            </div>
            <div id="dlg-buttons" style="margin-bottom:10px;">
                <span style="margin-top:10px;">操&nbsp;&nbsp;&nbsp;作:</span>
                <a id="inform" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveMem()"  style="width:90px;margin-left: 50px;">通知</a>
                <a id="submit_" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveMem()" style="width:90px;margin-left: 50px;">上报</a>
            </div>
            <div id="contact_template" style="margin-bottom:10px">
                <input name="operation_info" id="contact" class="easyui-textbox" data-options="multiline:true" required="true" editable="false" label="通知模板:" style="width:100%">
            </div>

            <div style="margin-bottom:10px">
                <input name="planName"  class="easyui-textbox" required="true" editable="false" label="所属预案:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="switch_logic" id="switch_logic"  class="easyui-textbox"  data-options="multiline:true" required="true" editable="false" label="分支要素:" style="width:100%">
            </div>
            <div id="switch_select" style="margin-bottom:10px">
                <span>分支选择:</span>
                <input name="E" id="isE" type="radio" class="easyui-validatebox" style="margin-left: 50px;"  value="0">是
                <input name="E" type="radio" class="easyui-validatebox" style="margin-left: 50px;"   value="1">否
            </div>
        </form>
    </div>

    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="finish()" style="width:90px">完成任务</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
    <script type="text/javascript">
        var url;
        function editMem(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑');
                $('#fm').form('load',row);
                if(row.operation_code==1){//显示上报按钮  为1
                    $("#submit_").show();
                    $("#inform").hide();
                    $("#contact_template").hide();
                }else {                   //显示通知按钮  为0
                    $("#inform").show();
                    $("#contact_template").show();
                    $("#submit_").hide();
                }
                if(row.to_switch=0){      //出顺序流是否指向分支节点  为0 隐藏
                    $("#switch_logic").hide();
                    $("#switch_select").hide();
                }
            }
            document.getElementById("isE").checked = true;//设置默认选中
        }
        function finish(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('确认','是否确定任务已经完成？',function(r){
                    if (r){
                        $.post('${ctx}/aid_task/finish',{ID:row.id,E:row.E},function(result){
                            if (result.status==0){
                                $('#dg').datagrid('reload');    // reload the user data
                            } else {
                                $.messager.show({    // show error message
                                    title: '错误',
                                    msg: result.msg
                                });
                            }
                        },'json');
                    }
                });
            }
        }

        function doSearch(){
            $('#dg').datagrid('load',{
                queryParam: $('#queryParam').val(),
                condition: $('#condition').val()
            });
        }

        /**
         * 转化时间格式
         * @param value
         * @returns {string}
         */
        function dateFormatter(value) {
            var date = new Date(value);
            var year = date.getFullYear().toString();
            var month = (date.getMonth() + 1);
            var day = date.getDate().toString();
            var hour = date.getHours().toString();
            var minutes = date.getMinutes().toString();
            var seconds = date.getSeconds().toString();
            if (month < 10) {month = "0" + month;}
            if (day < 10) {day = "0" + day;}
            if (hour < 10) {hour = "0" + hour;}
            if (minutes < 10) {minutes = "0" + minutes;}
            if (seconds < 10) {seconds = "0" + seconds;}
            return year + "-" + month + "-" + day + " " + hour + ":" + minutes + ":" + seconds;
        }

    </script>
</div>
</body>
</html>
